﻿/**
 * Create in 2012-3-29 上午10:49:48.
 */
package kit4j.common.lang;

/**
 * 固定长度的Integer数值类型。
 * 
 * @author MiniKnife
 *
 */
public class FixedLengthInteger extends FixedLengthNumber {

	private static final long serialVersionUID = 1L;
	
	private Integer number;

	/**
	 * @param length
	 */
	public FixedLengthInteger(int length) {
		super(length);
		
		number = 0;
	}

	/** 
	 * @see kit4j.common.lang.FixedLengthNumber#parseNumberFromString(java.lang.String)
	 */
	@Override
	protected Number parseNumberFromString(String str)
			throws NumberFormatException {
		return Integer.valueOf(str);
	}

	/** 
	 * @see kit4j.common.lang.FixedLengthNumber#parseStringFromNumber(java.lang.Number)
	 */
	@Override
	protected String parseStringFromNumber(Number num) {
		return String.valueOf(num.intValue());
	}

	/** 
	 * @see kit4j.common.lang.FixedLengthNumber#increase()
	 */
	@Override
	public void increase() throws NumberOutOfBoundException {
		++number;
		
		setNumber(number);
	}

	/** 
	 * @see kit4j.common.lang.FixedLengthNumber#decrease()
	 */
	@Override
	public void decrease() throws NumberOutOfBoundException {
		--number;
		
		setNumber(number);
	}
	
	/** 
	 * @see kit4j.common.lang.FixedLengthNumber#setNumber(java.lang.Number)
	 */
	@Override
	public void setNumber(Number num) throws NumberOutOfBoundException {
		this.number = num.intValue();
		
		super.setNumber(num);
	}

	/** 
	 * @see java.lang.Number#intValue()
	 */
	@Override
	public int intValue() {
		return number.intValue();
	}

	/** 
	 * @see java.lang.Number#longValue()
	 */
	@Override
	public long longValue() {
		return number.longValue();
	}

	/** 
	 * @see java.lang.Number#floatValue()
	 */
	@Override
	public float floatValue() {
		return number.floatValue();
	}

	/** 
	 * @see java.lang.Number#doubleValue()
	 */
	@Override
	public double doubleValue() {
		return number.doubleValue();
	}
	
	/**
	 * @see #getNumberAsString()
	 */
	@Override
	public String toString() {
		return getNumberAsString();
	}

}
